#!/usr/bin/env python
# -*- coding: UTF-8 -*-

try:
	import pdb
	import pygame
	import sys
	import utils
	from animatable import Animatable
	from menu import *
	from pygame.locals import *
except ImportError, err:
	print "Could not load %s module." % (err)
	sys.exit(2)

'''
Creature

Any and all sprites that move and attack should be instances or
subclasses of this class.

Needs a lot of work. It's currently hardcoded to always face South.
'''

class Creature(pygame.sprite.Sprite, Animatable):
	def __init__(self):
		pygame.sprite.Sprite.__init__(self)
		Animatable.__init__(self)
		self.full_image = utils.get_creature_surface(utils.ERWIN_3)
		self.mov_seq = 0
		self.frame = 0
		# character (0,0)
		(self.x, self.y) = (48, 48)
		# initial position
		self.x += (8 * 48)
		self.y += (4 * 48)
		self.rect = pygame.rect.Rect((self.x, self.y, 48, 48))
		self.image = pygame.surface.Surface(self.rect.size).convert()
		self.image.blit(self.full_image.subsurface(((64 * self.mov_seq, 64), (48, 48))), (0,0))
		self.image.set_colorkey(self.image.get_at((0,0)), RLEACCEL)

		self.MV = 3
		self.atk_range = 1
		self.action_menu_options = ('Move', 'Attack', 'Magic',
									'Rally', 'Tactics', 'Status')
		self.set_anim_params(48)


	def update(self):
		if self.moving:
			self.slide()
			self.rect.topleft = (self.x, self.y)

		# every 20 frames, rest on the other foot
		self.frame = (self.frame + 1) % 20
		if self.frame == 0:
			self.mov_seq  = (self.mov_seq + 1) % 2
			self.image.blit(self.full_image.subsurface(((64 * self.mov_seq, 64), (48, 48))), (0,0))

	def move(self, key):
		'''
		move() is NOT walk()
		move() moves the sprite, walk() makes the creature walk (eventually)

		We can cheat and simplify this method, since we know this
		object never moves unless the Battlefield does.
		'''
		if key in (K_UP, K_RIGHT, K_DOWN, K_LEFT):
			self.moving = key
			return key
		else:
			return 0

	def r_move(self, key):
		moved = self.move(key)
		if key == K_UP: self.moving = (moved and K_DOWN)
		elif key == K_RIGHT: self.moving = (moved and K_LEFT)
		elif key == K_DOWN: self.moving = (moved and K_UP)
		elif key == K_LEFT: self.moving = (moved and K_RIGHT)
		return self.moving


'''
These are some properties that a creature should have

	self.HP = 10
	self.AT = 0
	self.DF = 0
	self.MV = 3
	self.magic_AT = 0
	self.magic_DF = 0
	self.atk_range = 1
	self.cmd_range = 2

	self.magics = ()
	self.summons = ()
	self.is_commander = 0

	self.has_acted = 0
	self.tactic = 0

	self.facing = SOUTH
'''
